<?

class TAG extends OBJECT {
	function __construct( $id = 0, $create_new = false, $vars = false ) {
		global $DB;
		
		$this->type = "tag";
		$this->id	= (int) $id;
		
#		Load assigned object or most recent
		if( $id || !$create_new )
			$this->load( $this->type, $id );

#		Create new
		else
			$this->create( $this->type, is_string( $create_new )? $create_new : "..." );
	
	}
	
	
	public function get( $what ) {
		
		
		if( !isset( $this->values[ $what ])) {
			global $DB;
			
			if ( $what == "content" )
				 $this->values[ $what ] = $DB->get_key( $this->type, $this->id, "<%lang:{$DB->type( $this->type, 'table' )}.textid:long%> as content" );
			else $this->values[ $what ] = $this->values[ "meta" ]->{ $what };
		}

		return $this->values[ $what ];
	}
	
	public function uri() {
		
		return "/o/{$this->type}/". urlencode( $this->get( "name" )) ."/{$this->id}";
	}
	
	public function url() {
		
		return engine_get( "url" ) . $this->uri();
	}
	
	function render( $uri = true, $class = "" ) {
		
		if( $class )
			$class = " class='" . (( $class == "rand" )? "sze".rand(0,4)." col".rand(0,4)." weight".rand(0,4) : $class ) . "'";
		
		return ( $uri )?
			"<a href='{$this->uri()}'$class>{$this->get('name')}</a>" : "<span$class>{$this->get('name')}</span>";
	}
	

}


?>